home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9209.ARJ / 1009066A < prev    next >
Text File  |  1992-06-30  |  1KB  |  82 lines

  1.  
  2. /*
  3.     Listing 3
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <errno.h>
  8. #include <string.h>
  9. #include "enet_cs.h"
  10.  
  11. #define NOMOD 65535
  12.  
  13. FILE *fp;
  14.  
  15. char filename[100] = "node\"test tester\"::[test]file.txt";
  16. cs_write(long loc, int value)
  17. {
  18.  
  19.     char *sptr;
  20.  
  21.     while ((fp = fopen(filename, "a+")) == NULL){
  22.  
  23.         if (errno != NOMOD) {
  24.  
  25.             if ( (sptr = strerror(errno)) == NULL) {
  26.                 printf ("Unknown open error.\n");
  27.                 exit(0);
  28.             } else {
  29.                 sptr = strerror(errno);
  30.                 perror (sptr);
  31.                 exit(0);
  32.             }
  33.  
  34.         }
  35.  
  36.     };
  37.  
  38.     if (fseek (fp, loc*4, ORIGIN) != 0)
  39.         printf ("ERROR: fseek error in cs_write\n");
  40.  
  41.     if (fprintf (fp, "%d ", value) < 0)
  42.         printf ("ERROR: cs_write error\n");
  43.  
  44.     fclose (fp);
  45.  
  46.     return;
  47. }
  48.  
  49. int cs_read(long loc)
  50. {
  51.  
  52.     char *sptr;
  53.     int value;
  54.  
  55.     while ((fp = fopen(filename, "r")) == NULL){
  56.  
  57.         if (errno != NOMOD) {
  58.  
  59.             if ((sptr = strerror(errno)) == NULL) {
  60.                 printf ("Unknown open error.\n");
  61.                 exit(0);
  62.             } else {
  63.                 sptr = strerror(errno);
  64.                 perror (sptr);
  65.                 exit(0);
  66.             }
  67.  
  68.         }
  69.  
  70.     };
  71.  
  72.     if (fseek (fp, loc*4, ORIGIN) != 0)
  73.         printf ("ERROR: fseek error in cs_read\n");
  74.     if (fscanf (fp ,"%d", &value) == EOF)
  75.         printf ("ERROR: cs_read error\n");
  76.  
  77.     fclose (fp);
  78.  
  79.     return(value);
  80. }
  81.  
  82.